package com.wswy.wzcx.ui.fragment


import android.annotation.SuppressLint
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.che.libcommon.ui.BaseFragment
import com.che.libcommon.utils.RxBus
import com.wswy.wzcx.R
import com.wswy.wzcx.model.home.RouterUtils
import com.wswy.wzcx.module.GlobalConfigManager
import com.wswy.wzcx.module.InternalMsgCodeKt
import com.wswy.wzcx.statistics.StatTools
import com.wswy.wzcx.statistics.StatisticsId
import com.wswy.wzcx.ui.activity.news.ResultNewsActivity
import kotlinx.android.synthetic.main.fragment_fkdjresult.*

/**
 * 支付成功
 * A fragment with a Google +1 button.
 * Use the [FKDJResultFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class FKDJResultFragment : BaseFragment() {
    private var mParam1: Boolean? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            mParam1 = it.getBoolean(ARG_PARAM1)
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.fragment_fkdjresult, container, false)

        return view
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        if (mParam1 == true) {
            RxBus.getDefault().postWithCode(InternalMsgCodeKt.SUBMIT_COMPLETE_FKDJ, "")
            icon.setImageResource(R.drawable.finished)
            tv_pay_result.text = getString(R.string.pay_success)
            tv_pay_result_tip.text = getString(R.string.pay_success_tip)
        }



        GlobalConfigManager.getInstance().adsConf.getPayAd()?.run {

            if (!TextUtils.isEmpty(imgUrl) && !TextUtils.isEmpty(linkUrl)){
                img_ad.setImageURI(imgUrl,null)

                img_ad.setOnClickListener {

                    StatTools.sendClick(it.context,StatisticsId.paydone_ad)

                    RouterUtils.startTarget(it.context,linkTarget,linkUrl)
                    finish()
                }
            }

        }



//        tv_ok.postDelayed({
//
//            val ctx = context
//            if (!isFinish && ctx != null){
//                ResultNewsActivity.startPaySuccess(ctx)
//            }
//
//        },2000)


        tv_ok.setOnClickListener {
            finish()
        }
    }

    @SuppressLint("MissingSuperCall")
    override fun onResume() {
        super.onResume()
    }


    companion object {
        const val TAG = "FKDJResultFragment"
        private const val ARG_PARAM1 = "param1"

        fun newInstance(param1: Boolean): FKDJResultFragment {
            val fragment = FKDJResultFragment()
            val args = Bundle()
            args.putBoolean(ARG_PARAM1, param1)
            fragment.arguments = args
            return fragment
        }
    }

    override fun getFragmentTitle(): String {
        return "支付结果"
    }


}// Required empty public constructor
